//
//  WFMainTabbarController.m
//  WisdomFarm
//
//  Created by sky on 2017/10/24.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFMainTabbarController.h"
#import "WFHomeViewController.h"
#import "WFMapViewController.h"
#import "WFServiceViewController.h"
#import "WFSettingViewController.h"

#import "UIColor+WF.h"

@interface WFMainTabbarController ()<UITabBarControllerDelegate>

@end

@implementation WFMainTabbarController

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.delegate = self;
        
        [[UITabBar appearance] setTintColor:[UIColor themeColor]];
        
        WFHomeViewController *homeVC = [WFHomeViewController new];
        WFMapViewController *mapVC = [WFMapViewController new];
        WFServiceViewController *serviceVC = [WFServiceViewController new];
        WFSettingViewController *settingVC = [WFSettingViewController new];
        
        UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];
        UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:mapVC];
        UINavigationController *serviceNav = [[UINavigationController alloc] initWithRootViewController:serviceVC];
        UINavigationController *settingNav = [[UINavigationController alloc] initWithRootViewController:settingVC];

        
        homeNav.tabBarItem = [self itemWithTitle:@"首页"
                                normalImageName:@"tab_btn_home_no"
                              selectedImageName:@"tab_btn_home"];
        
        mapNav.tabBarItem = [self itemWithTitle:@"地图"
                               normalImageName:@"tab_btn_map_no"
                             selectedImageName:@"tab_btn_map"];
        
        serviceNav.tabBarItem = [self itemWithTitle:@"服务"
                                   normalImageName:@"tab_btn_service_no"
                                 selectedImageName:@"tab_btn_service"];
        
        settingNav.tabBarItem = [self itemWithTitle:@"关于"
                                   normalImageName:@"tab_btn_about_no"
                                 selectedImageName:@"tab_btn_about"];

        self.viewControllers = @[ homeNav, mapNav, serviceNav, settingNav ];

    }
    return self;
}

- (UITabBarItem *)itemWithTitle:(NSString *)title normalImageName:(NSString *)name selectedImageName:(NSString *)selectedName {
    UIImage *normalImage = [UIImage imageNamed:name];
    UIImage *selectedImage = [UIImage imageNamed:selectedName];
    return [[UITabBarItem alloc] initWithTitle:title image:normalImage selectedImage:selectedImage];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
